/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OLA_CLOUD_DEF_H
#define OLA_CLOUD_DEF_H

#ifdef __cplusplus
extern "C" {
#endif

/* 基础宏定义 */
#define CLOUD_COAP_WAIT_TIMEVAL 50 /* coap等待超时 */
#define CLOUD_M2M_NETWORK_CHK_TIMEVAL (1 * 1000) /* m2m 状态网络监测间隔 单位：ms */
#define CLOUD_HEARTBEAT_TIMEVAL (50 * 1000) /* 云端心跳间隔 单位：ms */
#define CLOUD_HEARTBEAT_MAX_TIMES 3 /* 云端心跳尝试最大次数 */
#define CLOUD_TOKEN_REFRESH_MAX_TIMES 4 /* 云端token刷新尝试最大次数 */
#define CLOUD_TOKEN_REFRESH_TIMEVAL 28 /* 云端token刷新时间为timeout的 28/32 */
#define CLOUD_TOKEN_REFRESH_TIMEBASE 5 /* 云端token刷新间隔为timeout的 1/32 (1>>5) */
#define CLOUD_ACCESS_TOKEN_LEN 40 /* 云端access token长度 */
#define CLOUD_REFRESH_TOKEN_LEN 40 /* 云端refresh token长度 */
#define TIMEOUT_SLEEP_MS 1000 /* s到ms的转换 */

/* 云端通信错误码 */
enum {
    /* 公共 */
    CLOUD_ERRCODE_NO_ERROR = 0, /* 无错误 */
    CLOUD_ERRCODE_REQ_PARAM_ERROR = 1, /* 请求参数错误 */
    CLOUD_ERRCODE_CLOUD_ERROR = 2, /* 云内部错误 */
    CLOUD_ERRCODE_APP_ERROR = 3, /* APP内部错误 */
    CLOUD_ERRCODE_DEV_ERROR = 4, /* 设备内部错误 */

    /* 云 -> 设备 */
    CLOUD_ERRCODE_REG_INFO_ERR = 5, /* 配网信息数据错误 */
    CLOUD_ERRCODE_UNAUTHORIZED = 6, /* 设备未认证，需要继续认证 */
    CLOUD_ERRCODE_DEV_CERT_AUTH_FAILED = 7, /* 设备证书认证失败 */
    CLOUD_ERRCODE_DEV_ACTIVATE_FAILED = 8, /* 设备激活失败 */
    CLOUD_ERRCODE_DEV_ACTIVATED = 9, /* 设备已激活 */
    CLOUD_ERRCODE_DEV_LOGIN_FAILED = 10, /* 设备登录失败 */
    CLOUD_ERRCODE_DEV_DELETED = 11, /* 设备已被删除 */
    CLOUD_ERRCODE_OBTAIN_ACCESS_TOKEN_FALIED = 12, /* 设备获取访问令牌失败 */
    CLOUD_ERRCODE_REFRESH_ACCESS_TOKEN_FALIED = 13, /* 刷新访问令牌失败 */
    CLOUD_ERRCODE_ACCESS_TOKEN_EXPIRED = 14, /* 访问令牌已过期 */
    CLOUD_ERRCODE_REFRESH_TOKEN_EXPIRED = 15, /* 刷新令牌过期 */
    CLOUD_ERRCODE_DEV_PROFILE_ERROR = 16, /* 设备Profile信息错误 */

    /* 设备 -> 云 */
    CLOUD_ERRCODE_DEV_OPERATE_FALIED = 17, /* 设备操作失败 */
    CLOUD_ERRCODE_DEV_SERVICE_SUBSCRIBED = 18, /* 设备服务已被订阅 */
};

#ifdef __cplusplus
}
#endif

#endif /* OLA_CLOUD_DEF_H */